home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 May / SGI IRIX 6.5 Applications 1999 May.iso / dist / impr_base.idb / usr / sbin / mkjtpr.z / mkjtpr
Text File  |  1998-05-04  |  22KB  |  800 lines

  1. #!/bin/sh 
  2. #Tag 0x00000700
  3. #**************************************************************************
  4. #*
  5. #*           Copyright (c) 1995 Silicon Graphics, Inc.
  6. #*            All Rights Reserved
  7. #*
  8. #*       THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  9. #*
  10. #* The copyright notice above does not evidence any actual of intended
  11. #* publication of such source code, and is an unpublished work by Silicon
  12. #* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  13. #* the property of Silicon Graphics, Inc. Any use, duplication or
  14. #* disclosure not specifically authorized by Silicon Graphics is strictly
  15. #* prohibited.
  16. #*
  17. #* RESTRICTED RIGHTS LEGEND:
  18. #*
  19. #* Use, duplication or disclosure by the Government is subject to
  20. #* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  21. #* Technical Data and Computer Software clause at DFARS 52.227-7013,
  22. #* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  23. #* Supplement. Unpublished - rights reserved under the Copyright Laws of
  24. #* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  25. #* Shoreline Blvd., Mountain View, CA 94039-7311
  26. #**************************************************************************
  27. #*
  28. #* File: mkjtpr
  29. #*
  30. #* $Revision: 1.5 $
  31. #*
  32. #* Description: Shell script for adding a printer directly connected
  33. #*              to the network to the System V spooling system.  Example
  34. #               are printers connected to HP JetDirect cards.
  35. #*
  36. #*    Usage: mkjtpr  [<local printer name>] 
  37. #                      [<name or IP address of network adaptor>]
  38. #*
  39. #*    Selection of the local model file will always be
  40. #*    done interactively.
  41. #*
  42. #*      ~lp/model/<printer_model> files that contain DEVICE=NETPRINT are
  43. #*      assumed to be valid choices for use with this script.  The user
  44. #*      is offered a list to choose from based on the files that
  45. #*      have the DEVICE=NETPRINT string.
  46. #*
  47. #* Updated for print 1.7 (major changes for print 1.7).  This script no
  48. #* longer parses the output of "lputil list".  It now uses
  49. #* /usr/lib/print/modelinfo and /usr/lib/print/modinfofltr to build
  50. #* the menus that the user sees.  This was done because with PPD files
  51. #* (introduced in Impressario 2.2) it is possible to have a large number
  52. #* of supported printers.  The older code for this routine could not handle
  53. #* a large number of printers (it would overflow string variables).
  54. #*
  55. #**************************************************************************
  56.  
  57.  
  58. # Well known directories and programs
  59.  
  60. LPUTIL_DIR=/usr/lib
  61. LPUTIL=$LPUTIL_DIR/lputil
  62. APPRES=/usr/bin/X11/appres
  63. AWK_DIR=/usr/bin
  64. AWK=$AWK_DIR/nawk
  65. PING_CMD="/usr/etc/ping -q -c3"
  66. ARP_CMD="/usr/etc/arp"
  67. GREP_CMD="/bin/egrep"
  68. OUT_FILT="/usr/bin/pg -s -p more... -e"
  69. SPOOL_DIR=/var/spool/lp
  70. INTERFACE_DIR=$SPOOL_DIR/interface
  71. LPSTAT=/usr/bin/lpstat
  72. CHKCONFIG=/sbin/chkconfig 
  73. OUTSOCK="OUTSOCK"  # An option in the model file that we update.
  74. INSOCK="INSOCK" # An option in the model file that we update.
  75. MODELINFO=/usr/lib/print/modelinfo
  76. MODELINFOFILTER="/usr/lib/print/modinfofltr -l netprinter"
  77.  
  78. # Global variables
  79.  
  80. PNAME=""
  81. NUM_MODELS=0
  82. NUM_DEVICES=0
  83. PMODEL_LIST=""
  84. PTYPE_LIST=""
  85. POPT_LIST=""
  86. TYPE_ID=""
  87. PORT_ID=""
  88. OUT_PORT_NUMBER=""
  89. IN_PORT_NUMBER=""
  90. TYPE_NAME=""
  91. MODEL_NAME=""
  92. OPTION_STR=""
  93. REMOTE_HOST=""
  94. DEV_LIST=""
  95. OUT_PORTS=""
  96. IN_PORTS=""
  97. NUM_VENDORSS=0
  98. VENDOR_ID=""
  99.  
  100.  
  101. #
  102. # Prints the program usage string
  103. #
  104. PrintUsage()
  105. {
  106.     echo "Usage: mkjtpr [<local printer name>] [<name or IP address of network adaptor>]"
  107. }
  108.  
  109. #
  110. # Checks that we are the super-user and verifies
  111. # that the System V spooling system is present
  112. #
  113. CheckPermSpooler()
  114. {
  115.     cid=`/usr/bin/id | $AWK '{print substr($1,index($1,"("))}'`;
  116.     if [ "$cid" != "(root)" ]; then
  117.         echo "You must be logged in as root to use this program."
  118.         exit 1;
  119.     fi
  120.     if [ ! -r $SPOOL_DIR ]; then
  121.         echo "The System V spooling system is not installed on this system."
  122.         exit 1
  123.     fi
  124. }
  125.  
  126.  
  127. #
  128. # Create a list of valid network card devices.  This pulls the data
  129. # from the Printers resource file.
  130. CreateNetDeviceList()
  131. {
  132. string=`$APPRES Printers | $GREP_CMD -i netprinter | $GREP_CMD -i "\*NETPRINTER\*netDevices" | $GREP_CMD ","`
  133.  
  134. DEV_LIST=`echo $string | $AWK -F\| '{print substr($1,index($1,"Network"))}' | nawk -F\% ' BEGIN { dosep = 0 } 
  135.         {
  136.             size=split($1,a,",")
  137.             count=1
  138.             mod=0
  139.             while(count<=size) {
  140.                if (mod==0) {
  141.                   if (dosep)
  142.                        printf("|")
  143.                    else
  144.                        dosep = 1
  145.                   printf("%s", a[count])
  146.                }
  147.                mod+=1
  148.                if (mod==3) mod=0
  149.                count+=1
  150.             }
  151.         }'`
  152.  
  153. OUT_PORTS=`echo $string | $AWK -F\| '{print substr($1,index($1,"Network"))}' | nawk -F\%  ' BEGIN { dosep = 0 }  
  154.         {
  155.             size=split($1,a,",")
  156.             count=1
  157.             mod=0
  158.             while(count<=size) {
  159.                if (mod==1) {
  160.                   if (dosep)
  161.                        printf("|")
  162.                    else
  163.                        dosep = 1
  164.                    sub(" ","",a[count])
  165.                    printf("%s", a[count])
  166.                }
  167.                mod+=1
  168.                if (mod==3) mod=0
  169.                count+=1
  170.             }
  171.         }'`
  172.  
  173.  
  174. IN_PORTS=`echo $string | $AWK -F\| '{print substr($1,index($1,"Network"))}' | nawk -F\%  ' BEGIN { dosep = 0 }
  175.         {
  176.             size=split($1,a,",")
  177.             count=1
  178.             mod=0
  179.             while(count<=size) {
  180.                if (mod==2) {
  181.                   if (dosep)
  182.                        printf("|")
  183.                    else
  184.                        dosep = 1
  185.                    sub(" ","",a[count])
  186.                    printf("%s", a[count])
  187.                }
  188.                mod+=1
  189.                if (mod==3) mod=0
  190.                count+=1
  191.             }
  192.         }'`
  193.  
  194.  
  195. NUM_DEVICES=`echo $string | $AWK -F\| '{print substr($1,index($1,"Network"))}' | nawk -F\| '
  196.         {
  197.             size=split($1,a,",")
  198.         } 
  199.         END { printf("%d\n", size/3) }'`
  200.  
  201. }
  202.  
  203.  
  204. #
  205. # If a list of network cards and network adaptors could not be parsed
  206. # from the Printers resource file in CreateNetDeviceList then build a default 
  207. # list that lists the HP cards.
  208. #
  209. BuildDefaultList()
  210. {
  211. DEV_LIST="Network Card Installed in Printer|HP JetDirect EX External Interface|HP JetDirect EX Plus3 Port 1|HP JetDirect EX Plus3 Port 2|HP JetDirect EX Plus3 Port 3"
  212.  
  213. OUT_PORTS="-1|9100|9100|9101|9102"
  214. IN_PORTS="-1|9100|9100|9101|9102"
  215.  
  216. NUM_DEVICES="5"
  217.  
  218. }
  219.  
  220. #
  221. # Displays a list of network printers
  222. #
  223. ShowNetList()
  224. {
  225.     echo "Supported Network Printer Types:"
  226.     echo $PTYPE_LIST | $AWK -F\| 'BEGIN { RS = "|" }
  227.     {
  228.         printf("\t%2d. %s\n", NR, $1)
  229.     }' | $OUT_FILT
  230. }
  231.  
  232. ShowNetDeviceList()
  233. {
  234.     echo "Supported Network Interface Types:"
  235.     echo $DEV_LIST | $AWK -F\| 'BEGIN { RS = "|" }
  236.         {
  237.             printf("\t%2d. %s\n", NR, $1)
  238.         }' | $OUT_FILT
  239. }
  240.  
  241.  
  242. #
  243. # Extracts the model file name from a string similar to:
  244. # "laserwriter_model%NETPRINTER%Apple LaserWriter II%FACEUP=0".
  245. # Would return "laserwriter_model".
  246. #
  247. GetModelFileName()
  248. {
  249.     MODEL_NAME=`echo $* | $AWK  -F\%  '{
  250.             printf("%s\n",$1)
  251.         }'`
  252. }
  253.  
  254.  
  255. #
  256. # Extracts the printer type from a string similar to:
  257. # "laserwriter_model%NETPRINTER%Apple LaserWriter II%FACEUP=0"
  258. # Would return "Apple LaserWriter II".
  259. #
  260. GetPrinterType()
  261. {
  262.     TYPE_NAME=`echo $* | $AWK -F\% '{
  263.             printf("%s\n",$3)
  264.         }'`
  265. }
  266.  
  267. #
  268. # Extract the TCP port number to use 
  269. #
  270. GetOutPortNumber()
  271. {
  272.     OUT_PORT_NUMBER=`echo $OUT_PORTS | $AWK -F\| '{
  273.             printf("%s\n",$i)
  274.         }' i=$1`
  275. }
  276.  
  277. #
  278. # Extract the TCP port number to use
  279. #
  280. GetInPortNumber()
  281. {
  282.     IN_PORT_NUMBER=`echo $IN_PORTS | $AWK -F\| '{
  283.             printf("%s\n",$i)
  284.         }' i=$1`
  285. }
  286.  
  287.  
  288. #
  289. # Extracts the printer model file options from a string similar to:
  290. # "laserwriter_model%NETPRINTER%Apple LaserWriter II%FACEUP=0"
  291. # Would return "FACEUP=0".
  292. #
  293. GetPrinterOptions()
  294. {
  295.     OPTION_STR=`echo $* | $AWK -F\% '{
  296.             printf("%s\n",$4)
  297.         }'`
  298. }
  299.  
  300.  
  301. #
  302. # Test for pure decimal positive integer input
  303. #
  304. # Expects $1 to be the value to check. Returns 0 if
  305. # OK, 1 if invalid positive integer or if more than one
  306. # argument specified
  307. #
  308. VerifyInt()
  309. {
  310.     if [ $# -eq 0 ]; then
  311.     return 0
  312.     fi
  313.     if [ $# -gt 1 ]; then
  314.     return 1
  315.     fi
  316.     echo $1 | $GREP_CMD -s '^[0-9]*$'
  317.     return $?
  318. }
  319.  
  320.  
  321. #
  322. # Test for a valid printer name (i.e. 14 chars max, A-Za-z0-9_
  323. # only and no spaces)
  324. #
  325. VerifyPname()
  326. {
  327.     if [ $# -gt 1 ]; then
  328.     return 1
  329.     fi
  330.     echo $1 | $GREP_CMD -s '^[A-Za-z0-9_]*$'
  331.     if [ $? -eq 1 ]; then
  332.     return 1
  333.     fi
  334.     if [ `echo $1 | $AWK '{ print length($1) }'` -gt 14 ]; then
  335.     return 1
  336.     else
  337.     return 0
  338.     fi
  339. }
  340.  
  341. #
  342. # Test for a properly constructed remote host name
  343. #
  344. VerifyHostname()
  345. {
  346.     if [ $# -gt 1 ]; then
  347.         return 1
  348.     fi
  349.     return 0
  350. }
  351.  
  352. # Check if we can ping the network card.  We can't do anything fancy
  353. # like connect to it since it will refuse connections if it is busy
  354. # printing.  This just makes sure it is on the net and can be pinged.
  355.  
  356. checkjetonnet()
  357. {
  358.  
  359.   if $CHKCONFIG network; then
  360.      :
  361.   else
  362.      echo "Networking has not been enabled on this system." 1>&2
  363.      return 1
  364.   fi
  365.  
  366.   host=$1
  367.  
  368.   # See if we can ping it.  We really use this to add an arp entry for the
  369.   # network device (ping will not return an error if there is an ARP entry    
  370.   # even if it could not ping the device).
  371.  
  372.   $PING_CMD $host 2> /dev/null 1> /dev/null
  373.  
  374.   if [ $? != 0 ]; then
  375.      echo "Printer $host name not known.  Check /etc/hosts or yp server entries." 1>&2
  376.      return 1
  377.   fi
  378.  
  379.   # Check the arp table to make sure we really got it.  NOTE: If printer was 
  380.   # on net and then removed it is possible there is still an ARP entry.  As
  381.   # long as there is an ARP entry we continue.            
  382.  
  383. ## Commented out because this may not work across routers
  384. ##
  385. ##  arp_string=`$ARP_CMD "$host"` 2> /dev/null 
  386. ##
  387. ##  echo $arp_string | $GREP_CMD "no entry" >> /dev/null 
  388. ##  if [ $? != 1 ]; then
  389. ##     echo "Could not ping network printer: $host.  Check network \nconnection to printer."
  390. ##     return 1
  391. ##  fi
  392. ##
  393. ##  echo $arp_string | $GREP_CMD "incomplete" >> /dev/null 
  394. ##  if [ $? != 1 ]; then
  395. ##     echo "Could not ping network printer: $host.  Check network \nconnection to printer."
  396. ##     return 1
  397. ##  fi
  398.  
  399.   return 0
  400.  
  401. }
  402.  
  403.  
  404. # Check for a duplicate printer name. Returns 0 if dup,
  405. # 1 if name is unique
  406. #
  407. CheckDupName()
  408. {
  409.     /bin/ls $SPOOL_DIR/member/$1 2> /dev/null 1> /dev/null
  410.     return $?
  411. }
  412.  
  413.  
  414. #
  415. # Query user for a name for the local printer
  416. #
  417. QueryLocalName()
  418. {
  419.     while [ "$PNAME" = "" ]; do
  420.         echo "Enter new printer name (14 chars max.): \c"
  421.         read PNAME
  422.         VerifyPname $PNAME
  423.         if [ $? -eq 1 ]; then
  424.             echo "Invalid response: Name must be 14 chars (A-Za-z0-9_ only)"
  425.             PNAME=""
  426.         fi
  427.         if [ "$PNAME" = "" ]; then
  428.             continue
  429.         fi
  430.         CheckDupName $PNAME
  431.         if [ $? -eq 0 ]; then
  432.             echo " "
  433.             echo "WARNING: Printer $PNAME already exists."
  434.             echo '\nChoose a new name (y/n)[y]? \c'
  435.             read yn
  436.             if [ \( "$yn" != "n" \) -a \( "$yn" != "N" \) ]; then
  437.                 PNAME=""
  438.             fi
  439.         fi
  440.     done
  441. }
  442.  
  443.  
  444. #########################################################################
  445. #
  446. # Main program
  447. #
  448.  
  449. #
  450. # Ensure that we are root and that the main System V
  451. # spooling system directory is present
  452. #
  453. CheckPermSpooler
  454.  
  455. #
  456. # Get command line arguments, if any.
  457. #
  458. case $# in
  459.     0) ;;
  460.     1) PNAME=$1
  461.        ;;
  462.     2) PNAME=$1
  463.        REMOTE_HOST=$2
  464.        ;;
  465.     *) PrintUsage
  466.        exit 1
  467.        ;;
  468. esac
  469. #
  470. # Make sure we have a remote printer host
  471. #
  472. if [ "$REMOTE_HOST" = "" ]; then
  473.     while [ "$REMOTE_HOST" = "" ]; do
  474.         echo "Enter remote printer name (network name or IP address): \c"
  475.         read REMOTE_HOST
  476.         VerifyHostname $REMOTE_HOST
  477.         if [ $? -eq 1 ]; then
  478.             echo "Invalid response: Improperly constructed hostname"
  479.             REMOTE_HOST=""
  480.         fi
  481.     done
  482.     echo " "
  483. fi
  484.  
  485. echo "Testing connection to printer: $REMOTE_HOST...\n"
  486.  
  487. checkjetonnet $REMOTE_HOST
  488. if [ $? -eq 1 ]; then
  489.    echo "\nContinue anyway using $REMOTE_HOST as remote printer name(y/n)[y]? \c"
  490.    read yn
  491.    if [ \( "$yn" != "y" \) -a \( "$yn" != "Y" \) ]; then
  492.       exit 1
  493.    fi
  494. fi
  495.  
  496. #
  497. # Query user for a name for this printer
  498. #
  499. if [ "$PNAME" = "" ]; then
  500.     QueryLocalName
  501.     echo " "
  502. else
  503.     echo "Requested local printer name: $PNAME\n"
  504.     VerifyPname $PNAME
  505.     if [ $? -eq 1 ]; then
  506.         echo "Error: Local printer name must be 14 chars max (A-Za-z0-9_ only)"
  507.         PNAME=""
  508.         QueryLocalName
  509.         echo " "
  510.     fi
  511.     CheckDupName $PNAME
  512.     if [ $? -eq 0 ]; then
  513.         echo " "
  514.         echo "WARNING: Printer $PNAME already exists."
  515.         echo '\nChoose a new name (y/n)[y]? \c'
  516.         read yn
  517.         if [ \( "$yn" != "n" \) -a \( "$yn" != "N" \) ]; then
  518.             PNAME=""
  519.             QueryLocalName
  520.             echo " "
  521.         fi
  522.     fi
  523. fi
  524.  
  525. echo " "
  526. #
  527. # Use modelinfo and modinfofltr to build menus of supported printer
  528. # vendors and printer models.
  529. #
  530. echo "Determining printer vendor list..."
  531. echo " "
  532.  
  533. # The outer loop is because we allow the user to press return onthe
  534. # secoond menu to jump back to the first menu.
  535.  
  536. GOT_VENDOR_ID=""
  537. while [ "$GOT_VENDOR_ID" = "" ]; do
  538.  
  539.    # Get the user choice of vendor.  User sees something like:
  540.    # 1. GENERIC
  541.    # 2. HP
  542.    # 3. TEK
  543.  
  544.    VENDOR_ID=""
  545.    while [ "$VENDOR_ID" = "" ]; do
  546.       MODELS_LIST=`$MODELINFO | $MODELINFOFILTER`
  547.       NUM_VENDORS=$?  # modinfoftr returns number of menu items
  548.       echo "$MODELS_LIST" | $OUT_FILT
  549.       if [ $NUM_VENDORS -eq  -1 ]; then
  550.           echo "ERROR. $MODELINFOFILTER returns -1.  -1 indicates"
  551.           echo "program called with invalid arguments."
  552.       fi
  553.       if [ $NUM_VENDORS -eq 0 ]; then
  554.         echo "ERROR: None of the printer drivers installed on this system support"
  555.         echo "       driving a network printer.  Check the model scripts in "
  556.         echo "       /var/spool/lp/model.  Printers that are supported will have "
  557.         echo "       the string\" DEVICE=NETPRINT\" near the top of the model file."    
  558.         echo " "
  559.         echo "       Note that this script attempts to setup a driver that directly"    
  560.         echo "       drives the network printer.  You might wish to spool files to"
  561.         echo "       a remote workstation that, in turn, will forward them to the"
  562.         echo "       network printer.  Use the mknetpr script to do that."
  563.         exit 1
  564.       fi
  565.       echo " "
  566.       echo "Select printer vendor to use: \c"
  567.       read VENDOR_ID
  568.       VerifyInt $VENDOR_ID
  569.       if [ $? -eq 1 ]; then
  570.            echo "Invalid response: must be number between 1 and $NUM_VENDORS"
  571.            VENDOR_ID=""
  572.       fi
  573.       if [ "$VENDOR_ID" = "" ]; then
  574.            continue
  575.       fi
  576.       if [ \( $VENDOR_ID -eq 0 \) -o \( $VENDOR_ID -gt $NUM_VENDORS \) ]; then
  577.            echo "Invalid response: must be between 1 and $NUM_VENDORS"
  578.            VENDOR_ID=""
  579.       fi
  580.    done
  581.  
  582.    GOT_VENDOR_ID="1"  # Force exit from main loop
  583.  
  584.    # Now list the printer drivers supported for the selected vendor:
  585.    # Get user choice for model. User sees something like:
  586.  
  587.    # 1. APPLE LASERWRITER II
  588.    # 2. APPLE LASERWRITER IIF
  589.    # 3. APPLE LASERWRITER IIG
  590.    # 4. APPLE LASERWRITER IINT
  591.    # 5. APPLE LASERWRITER IINTX
  592.    # 6. APPLE LASERWRITER PLUS
  593.  
  594.    TYPE_ID=""
  595.    while [ "$TYPE_ID" = "" ]; do
  596.  
  597.       $MODELINFO | $MODELINFOFILTER -v$VENDOR_ID | egrep -i "\(POSTSCRIPT\)" 2> /dev/null 1> /dev/null
  598.       PPD_FOUND=$?
  599.  
  600.       $MODELINFO | $MODELINFOFILTER -v$VENDOR_ID | egrep "IMPRESSARIO LICENSE REQUIRED" 2> /dev/null 1> /dev/null
  601.       LICENSE_NEEDED=$?
  602.  
  603.       echo " "
  604.       MODELS_LIST=`$MODELINFO | $MODELINFOFILTER -v$VENDOR_ID`
  605.       NUM_MODELS=$?  # modinfoftr returns number of menu items
  606.       echo "$MODELS_LIST" | $OUT_FILT
  607.       if [ $NUM_MODELS -eq  -1 ]; then
  608.           echo "ERROR. $MODELINFOFILTER returns -1.  -1 indicates"
  609.           echo "program called with invalid arguments."
  610.       fi
  611.  
  612.       if [ $NUM_MODELS -eq  0 ]; then
  613.          echo "ERROR: No network printers appear to be supported for this choice."
  614.          echo "       Check that print software has been installed."
  615.          if [ "$NUM_VENDORS" = "1" ]; then
  616.             exit 1
  617.          fi
  618.          echo ""
  619.          echo "Press Enter to return to last menu.\c"
  620.          read TYPE_ID
  621.          TYPE_ID=1         # Bogus value to get out of this loop
  622.          GOT_VENDOR_ID=""  # Re-start main loop to go back to last menu
  623.          continue
  624.       fi
  625.  
  626.       if [ "$PPD_FOUND" = "0" ]; then
  627.       echo ""
  628.         echo "NOTE: Printer model names followed by \"(POSTSCRIPT)\" will only work"
  629.         echo "with printers that have built-in PostScript support.  Some of"
  630.         echo "these printers do not come with built-in PostScript and it must"
  631.         echo "be purchased from the printer vendor as a separate option."
  632.       fi
  633.  
  634.       if [ "$LICENSE_NEEDED" = "0" ]; then
  635.         echo ""
  636.         echo "Printer model names followed by \"(IMPRESSARIO LICENSE REQUIRED)\" will"
  637.         echo "need an optional Impressario license.  See the Impressario release notes"
  638.         echo "for details or the file /usr/lib/print/data/psrip_expired_msg"
  639.       fi
  640.  
  641.       echo ""
  642.       echo "Select printer model to use (press Enter for last menu): \c"
  643.       read TYPE_ID
  644.       if [ "$TYPE_ID" = "" ]; then
  645.          TYPE_ID=1         # Bogus value to get out of this loop
  646.          GOT_VENDOR_ID=""  # Re-start main loop to go back to last menu
  647.          echo ""
  648.          continue
  649.       fi
  650.       VerifyInt $TYPE_ID
  651.       if [ $? -eq 1 ]; then
  652.            echo "Invalid response: must be number between 1 and $NUM_MODELS"
  653.            TYPE_ID=""
  654.       fi
  655.       if [ \( $TYPE_ID -eq 0 \) -o \( $TYPE_ID -gt $NUM_MODELS \) ]; then
  656.            echo "Invalid response: must be between 1 and $NUM_MODELS"
  657.            TYPE_ID=""
  658.       fi
  659.    done
  660.  
  661. done
  662.  
  663. #
  664. # Look for names of network devices (JetDirect, built-in card, etc. )
  665. echo ""
  666. echo "Determining supported network interface cards..."
  667. echo ""
  668. CreateNetDeviceList
  669. if [ $NUM_DEVICES -eq 0 ]; then
  670.     BuildDefaultList
  671. fi
  672. ShowNetDeviceList
  673.  
  674. echo " "
  675.  
  676. #
  677. # Query user for network interface type 
  678. #
  679. while [ "$PORT_ID" = "" ]; do
  680.     echo "Enter interface type number: \c"
  681.     read PORT_ID
  682.     VerifyInt $PORT_ID
  683.     if [ $? -eq 1 ]; then
  684.         echo "Invalid response: Type must be number between 1 and $NUM_DEVICES"
  685.         PORT_ID=""
  686.     fi
  687.     if [ "$PORT_ID" = "" ]; then
  688.         continue
  689.     fi
  690.     if [ \( $PORT_ID -eq 0 \) -o \( $PORT_ID -gt $NUM_DEVICES \) ]; then
  691.         echo "Invalid response: Type must be between 1 and $NUM_DEVICES"
  692.         PORT_ID=""
  693.     fi
  694. done
  695.  
  696. #
  697. # Inform the user of what comes next
  698. #
  699. echo " "
  700. echo "Installing printer $PNAME..."
  701. echo " "
  702.  
  703. #
  704. # Get the model info string for the selected printer and pull out
  705. # the parts we need.
  706. #
  707.  
  708. modelstring=`$MODELINFO | $MODELINFOFILTER -v$VENDOR_ID -c$TYPE_ID`
  709. if [ $? -eq  -1 ]; then
  710.     echo "ERROR. $MODELINFOFILTER returns -1.  -1 indicates"
  711.     echo "program called with invalid arguments."
  712. fi
  713.  
  714. GetModelFileName $modelstring
  715. GetPrinterType $modelstring
  716. GetPrinterOptions $modelstring
  717. GetOutPortNumber $PORT_ID
  718. GetInPortNumber $PORT_ID
  719.  
  720. if [ "$OUT_PORT_NUMBER" != "-1" ]; then
  721.   OPTION_STR="$OPTION_STR $OUTSOCK=$OUT_PORT_NUMBER"
  722. fi
  723.  
  724. if [ "$IN_PORT_NUMBER" != "-1" ]; then
  725.   OPTION_STR="$OPTION_STR $INSOCK=$IN_PORT_NUMBER"
  726. fi
  727.  
  728. #
  729. # Install the printer. We use awk to execute the lputil command
  730. # because we want the OPTION_STR strings handled properly (i.e.
  731. # with the proper quoting).  
  732. #
  733. echo $LPUTIL add /var/spool/lp/devices/jet $MODEL_NAME $PNAME \
  734.             NETPRINTER=\'\"$REMOTE_HOST\"\'     \
  735.             NAME=\'\"$TYPE_NAME\"\' $OPTION_STR | $AWK '{
  736.         rv = system($0)
  737.         exit rv
  738.     }'
  739. if [ $? -ne 0 ]; then
  740.     echo "ERROR: Installation of new printer failed."
  741.     echo "       $LPUTIL command failed."
  742.     exit 1
  743. fi
  744.  
  745. #
  746. # Inform the user of what has happened
  747. #
  748. echo " "
  749. echo "Network Printer $PNAME has been installed"
  750. echo " "
  751. echo "Here is your printing environment:"
  752. echo " "
  753. $LPSTAT -t | $OUT_FILT
  754.  
  755. # Give user some background info on trouble-shooting, etc.
  756.  
  757. echo ""
  758. echo ""
  759. echo "Trouble shooting tips:"
  760. echo ""
  761. echo "If you have problems printing to the network printer first verify"
  762. echo "that you can ping the printer with the command:"
  763. echo " "
  764. echo "  $PING_CMD $REMOTE_HOST"
  765. echo " "
  766. echo "If the ping fails verify that the printer is connected and configured"
  767. echo "correctly (this includes setting the IP address, netmask, etc. on"
  768. echo "the printer).  Some printers must be power-cycled after setting up"
  769. echo "their network card."
  770. echo " "
  771. echo "If you can ping the network printer but can not print then you may"
  772. echo "also need to verify that the TCP port number used to connect to"
  773. echo "the network printer (or network adaptor) is correct.  The port "
  774. echo "number that the print spooler will use to communicate with the network"
  775. echo "printer is specified in the printer model file.  This command will "
  776. echo "return the port number in use: "
  777. echo " "
  778. echo "     $GREP_CMD $OUTSOCK $INTERFACE_DIR/$PNAME | $GREP_CMD -v NET"
  779. echo " "
  780. echo "This command returns:"
  781. echo " "
  782. $GREP_CMD $OUTSOCK $INTERFACE_DIR/$PNAME | $GREP_CMD -v NET
  783. echo " "
  784. echo "You might verify with your printer vendor that the TCP port number "
  785. echo "listed above is correct.  Edit this file to change the port number:"
  786. echo " "
  787. echo "     $INTERFACE_DIR/$PNAME "
  788. echo " "
  789. echo "You can also turn on debugging and print with this command:"
  790. echo " "
  791. echo "  lp -d$PNAME -overbose /etc/group"
  792. echo " "
  793. echo "Debug messages from the print job are logged to: $SPOOL_DIR/log"
  794.  
  795. #
  796. # Return a successful exit code
  797. #
  798. exit 0
  799.